package com.woniuxy.special.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class CommonUtil {
    /**
     * 任意对象转MAP
     */
    public static <E> Map<String, String> obj2Map(E e) {
        Map<String, String> map = new HashMap<>();
        for (Field field : e.getClass().getDeclaredFields()) {
            field.setAccessible(true);
            try {
                map.put(field.getName(), String.valueOf(field.get(e)));
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            }
        }
        return map;
    }
}
